//
//  HMCircleViewController.m
//  localLife
//
//  Created by Limonwei on 15/11/23.
//  Copyright © 2015年 heima. All rights reserved.
//

#import "HMCircleViewController.h"
#import "HMCircleModel.h"
#import "HMCircleCollectionViewCell.h"

@interface HMCircleViewController ()<UICollectionViewDataSource,UICollectionViewDelegate>
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
@property (weak, nonatomic) IBOutlet UICollectionViewFlowLayout *flowLayout;


@property(nonatomic,strong)HMCircleModelList *model;

@end


static NSString *ID= @"HMCircleCollectionViewCell";

@implementation HMCircleViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self SHOWloadView];
    
    self.titltLabel.text = @"圈子";
    
    [self performSelector:@selector(dismissLoadView) withObject:nil afterDelay:2];
    
    self.leftButton.hidden = YES;
    
    //如果Stroyboard中有 UICollectionViewCell 我们就不需要注册
    //
    
//    [_collectionView registerNib:[UINib nibWithNibName:ID bundle:nil] forCellWithReuseIdentifier:ID];
    
    [_flowLayout setSectionInset:UIEdgeInsetsMake(20, 10, 10, 10)];
    
    _flowLayout.itemSize = CGSizeMake([UIScreen mainScreen].bounds.size.width/5, [UIScreen mainScreen].bounds.size.height/5);
    
    _flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
    
}


-(void)viewWillAppear:(BOOL)animated{
    
    
    [super viewWillAppear:animated];
    
    [self getData];
    
}

-(void)getData{
    
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    
    [HMAFHTTPClient getClrcleWithParams:param withSuccessBlock:^(HMCircleModelList *model) {
        //
        //赋值
        _model = model;
        //刷新ReloadData ,刷新UI
        [_collectionView reloadData];
        NSLog(@"xxx");
    } withFailedBlock:^(NSError *error) {
        //
    }];

}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    return _model.list.count;
    
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    HMCircleCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath];
    
    cell.model = _model.list[indexPath.row];
    
    return cell;
    
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    NSLog(@"点击了第%ld个",indexPath.row);
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end























